package com.product.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.product.common.annotation.Log;
import com.product.common.core.controller.BaseController;
import com.product.common.core.domain.AjaxResult;
import com.product.common.enums.BusinessType;
import com.product.business.domain.EnterpriseInfo;
import com.product.business.service.IEnterpriseInfoService;
import com.product.common.utils.poi.ExcelUtil;
import com.product.common.core.page.TableDataInfo;

/**
 * 生产企业信息Controller
 *
 * @author wanghui
 * @date 2022-08-20
 */
@RestController
@RequestMapping("/business/enterprise")
public class EnterpriseInfoController extends BaseController {
    @Autowired
    private IEnterpriseInfoService enterpriseInfoService;

    /**
     * 查询生产企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnterpriseInfo enterpriseInfo) {
        startPage();
        List<EnterpriseInfo> list = enterpriseInfoService.selectEnterpriseInfoList(enterpriseInfo);
        return getDataTable(list);
    }

    /**
     * @param enterpriseInfo 企业信息
     * @return {@link TableDataInfo }
     * @Description 获取通过审核的企业
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:list')")
    @GetMapping("/listpass")
    public TableDataInfo listCheckPass(EnterpriseInfo enterpriseInfo) {
        startPage();
        enterpriseInfo.setCompanyStatus("0");
        List<EnterpriseInfo> list = enterpriseInfoService.selectEnterpriseInfoList(enterpriseInfo);
        return getDataTable(list);
    }

    /**
     * @param enterpriseInfo 企业信息
     * @return {@link TableDataInfo }
     * @Description 获取等待审核的企业
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:list')")
    @GetMapping("/listwait")
    public TableDataInfo listCheckWait(EnterpriseInfo enterpriseInfo) {
        startPage();
        enterpriseInfo.setCompanyStatus("1");
        List<EnterpriseInfo> list = enterpriseInfoService.selectEnterpriseInfoList(enterpriseInfo);
        return getDataTable(list);
    }

    /**
     * @param enterpriseInfo 企业信息
     * @return {@link TableDataInfo }
     * @Description 获取待整改的企业
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:list')")
    @GetMapping("/listrectify")
    public TableDataInfo listCheckRectify(EnterpriseInfo enterpriseInfo) {
        startPage();
        enterpriseInfo.setCompanyStatus("2");
        List<EnterpriseInfo> list = enterpriseInfoService.selectEnterpriseInfoList(enterpriseInfo);
        return getDataTable(list);
    }

    /**
     * @param enterpriseInfo 企业信息
     * @return {@link TableDataInfo }
     * @Description 获取已注销的企业
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:list')")
    @GetMapping("/listcancel")
    public TableDataInfo listCheckCancel(EnterpriseInfo enterpriseInfo) {
        startPage();
        enterpriseInfo.setCompanyStatus("3");
        List<EnterpriseInfo> list = enterpriseInfoService.selectEnterpriseInfoList(enterpriseInfo);
        return getDataTable(list);
    }


    /**
     * 导出生产企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:export')")
    @Log(title = "生产企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnterpriseInfo enterpriseInfo) {
        List<EnterpriseInfo> list = enterpriseInfoService.selectEnterpriseInfoList(enterpriseInfo);
        ExcelUtil<EnterpriseInfo> util = new ExcelUtil<EnterpriseInfo>(EnterpriseInfo.class);
        util.exportExcel(response, list, "生产企业信息数据");
    }

    /**
     * 获取生产企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId) {
        return AjaxResult.success(enterpriseInfoService.selectEnterpriseInfoByCompanyId(companyId));
    }

    /**
     * 新增生产企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:add')")
    @Log(title = "生产企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnterpriseInfo enterpriseInfo) {
        return toAjax(enterpriseInfoService.insertEnterpriseInfo(enterpriseInfo));
    }

    /**
     * 修改生产企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:edit')")
    @Log(title = "生产企业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnterpriseInfo enterpriseInfo) {
        return toAjax(enterpriseInfoService.updateEnterpriseInfo(enterpriseInfo));
    }

    /**
     * 删除生产企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprise:remove')")
    @Log(title = "生产企业信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds) {
        return toAjax(enterpriseInfoService.deleteEnterpriseInfoByCompanyIds(companyIds));
    }
}
